package com.cssw.fyzb.tps.api.live;

import com.cssw.fyzb.tps.client.LiveClient;
import com.cssw.fyzb.tps.model.vo.OptLiveStreamVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Feng Chen
 */
@Function(description = "创建混流", parameters = {
        @Parameter(name = "liveId", type = Type.String, description = "混流会话编号", required = true),
        @Parameter(name = "params", type = Type.String, description = "混流参数", required = true),
})
@Component
public class CreateMixLiveStream implements Action {

    @Autowired
    private LiveClient liveClient;

    private static final Logger logger = LoggerFactory.getLogger(CreateMixLiveStream.class);

    @Override
    public Response execute(Request request) throws Exception {
        String liveId = request.getString("liveId");
        String params = request.getString("params");
        try {
            OptLiveStreamVo vo = liveClient.createMixLiveStream(liveId, params);
            return Response.success().put("data", vo);
        } catch (Exception e) {
            logger.error("", e);
        }
        return Response.fail("操作异常");
    }


}
